package com.work.intelligent_transportation2;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.work.intelligent_transportation2.fragment.EnvironmentWeatherSystemFragment;

import Api.Environment_api;

public class EnvironmentActivity extends AppCompatActivity {

    private TextView textView3;
    private TextView textView4;
    private TextView textView5;
    private TextView textView6;
    private TextView textView7;
    private TextView textView8;
    private EditText edWendu;
    private EditText edShidu;
    private EditText edguanzhao;
    private EditText edco2;
    private EditText edpm25;
    private EditText eddaolu;
    private Switch switch1;
    private Button button;
    SharedPreferences SP;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_environment);
        initView();
        SP=getSharedPreferences("Environ",MODE_PRIVATE);
    }

    public void button(View view) {
        int wendu = Integer.parseInt(edWendu.getText().toString());
        int co2 = Integer.parseInt(edco2.getText().toString());
        int Shidu = Integer.parseInt(edShidu.getText().toString());
        int pm2_5 = Integer.parseInt(edpm25.getText().toString());
        int guanzhao = Integer.parseInt(edguanzhao.getText().toString());
        int daolu = Integer.parseInt(eddaolu.getText().toString());
        SharedPreferences.Editor editor= SP.edit();
        if (wendu!=0){
            editor.putInt("温度",wendu);
        }else {
            editor.putInt("温度",0);
        }
        if (co2!=0){
            editor.putInt("co2",co2);
        }else {
            editor.putInt("co2",0);
        }
        if (Shidu!=0){
            editor.putInt("湿度",Shidu);
        }else {
            editor.putInt("湿度",0);
        }
        if (pm2_5!=0){
            editor.putInt("pm2_5",pm2_5);
        }else {
            editor.putInt("pm2_5",0);
        }
        if (guanzhao!=0){
            editor.putInt("光照",guanzhao);
        }else {
            editor.putInt("光照",0);
        }
        if (daolu!=0){
            editor.putInt("道路",daolu);
        }else {
            editor.putInt("道路",0);
        }
        editor.apply();
        finish();
    }

    private void initView() {
        textView3 = (TextView) findViewById(R.id.textView3);
        textView4 = (TextView) findViewById(R.id.textView4);
        textView5 = (TextView) findViewById(R.id.textView5);
        textView6 = (TextView) findViewById(R.id.textView6);
        textView7 = (TextView) findViewById(R.id.textView7);
        textView8 = (TextView) findViewById(R.id.textView8);
        edWendu = (EditText) findViewById(R.id.ed_wendu);
        edShidu = (EditText) findViewById(R.id.ed_shidu);
        edguanzhao = (EditText) findViewById(R.id.edguanzhao);
        edco2 = (EditText) findViewById(R.id.edco2);
        edpm25 = (EditText) findViewById(R.id.edpm2_5);
        eddaolu = (EditText) findViewById(R.id.eddaolu);
        switch1 = (Switch) findViewById(R.id.switch1);
        button = (Button) findViewById(R.id.button);
    }
}